package framework.formfields;

import java.lang.reflect.Field;
import java.text.SimpleDateFormat;

import framework.FormField;
import framework.annotation.*;

public class FormDateField extends FormField {

	String dataFormat = "dd/MM/yyyy";
	public FormDateField(Field field) throws SecurityException,
		NoSuchFieldException {
		super(field);
		if(field.isAnnotationPresent(FormFieldDataFormat.class)){
			this.dataFormat = field.getAnnotation(FormFieldDataFormat.class).value();
		}
	}

	public String gerarLinha(Object objeto) throws Exception, Throwable {
		SimpleDateFormat formatter = new SimpleDateFormat(dataFormat);  
		return "<tr> <td>" + getLabel() + "</td>" + "<td><INPUT TYPE=\"DATE\" NAME=\"" + getField().getName() + "\" VALUE=\"" + 
			formatter.format(getField().get(objeto)) + "\"</td> </tr>\n";
	}
}
